package com.iostream;

import java.io.*;

/**
 * @Author WaveHi
 * @Date 20/8/2021 下午 4:08
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Test the use of java.io.ObjectInputStream anf java.io.ObjectOutputStream
 */
public class TestObjectStream {

    public static void main(String[] args) {
        ObjectOutputStream oos = null;
        ObjectInputStream ois = null;

        try {
            //获取数据存取的位置
            File destFile1 = new File("day11/object/object1.dat");

            //获取流
            FileOutputStream fos1 = new FileOutputStream(destFile1);
            oos = new ObjectOutputStream(fos1);

            //获取需要存取的数据
            String s1 = "Wow!";

            //数据的存取
            oos.writeObject(s1);
            oos.flush();
            System.out.println("Data transfer completed!");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //资源的关闭
            if(oos != null) {

                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }


    }

}
